package ee.ttu.rakarh.commands;

import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import ee.ttu.rakarh.model.data.entities.TypeAttribute;
import ee.ttu.rakarh.services.ItemAttributeService;

public class PrepareNewItemForm implements Command {
	private static final Logger LOG = Logger.getLogger(PrepareNewItemForm.class);
	@Override
	public Boolean execute(HttpServletRequest request,
			HttpServletResponse response) {

		Collection<TypeAttribute> itemAttributes = new ArrayList<TypeAttribute>();
		ItemAttributeService itemAttrinuteService = new ItemAttributeService();
		
		try{
			int typeId = Integer.parseInt(request.getParameter("type"));
			itemAttributes = itemAttrinuteService.getTypeAttributesByTypeId(typeId);
		}catch (Exception e) {
			LOG.error(e);
		}
		request.setAttribute("itemAttributes", itemAttributes);
		return true;
	}

}
